package org.jiajie.coffeecodes.ali;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.DelayQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author jie
 */
public class DelayQueueTest {


    public static void main(String[] args) throws InterruptedException {
        DelayQueue<TestDelayed> delayedQueue = new DelayQueue<TestDelayed>();
        delayedQueue.offer(new TestDelayed("aaa", 5, TimeUnit.SECONDS));
        delayedQueue.offer(new TestDelayed("ccc", 1, TimeUnit.SECONDS));
        delayedQueue.offer(new TestDelayed("bbb", 3, TimeUnit.SECONDS));

        Logger logger = LoggerFactory.getLogger(DelayQueueTest.class);
        logger.info(((TestDelayed) delayedQueue.take()).getStr());
        logger.info(((TestDelayed) delayedQueue.take()).getStr());
        logger.info(((TestDelayed) delayedQueue.take()).getStr());
    }
}
